import 'package:hi_common/util/color.dart';
import 'package:hi_common/util/format_utils.dart';
import 'package:flutter/material.dart';

import '../http/model/video_detail_mo.dart';

class VideoToolBar extends StatefulWidget {
  final VideoDetailMo model;
  final VoidCallback? onLike;
  final VoidCallback? unLike;
  final VoidCallback? onCoin;
  final VoidCallback? onFavorite;
  final VoidCallback? unFavorite;
  final VoidCallback? onShared;

  const VideoToolBar(
      {super.key,
      required this.model,
      this.onLike,
      this.unLike,
      this.onCoin,
      this.onFavorite,
      this.unFavorite,
      this.onShared});

  @override
  State<StatefulWidget> createState() {
    return _VideoToolBarState();
  }
}

class _VideoToolBarState extends State<VideoToolBar> {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        _vSmallIconText(Icons.thumb_up_alt_rounded,
            countFormat(widget.model.videoInfo.like), tiny: widget.model.isLike,
            onClick: () {
          var isLike = widget.model.isLike;
          if (isLike) {
            widget.unLike?.call();
          }else{
            widget.onLike?.call();
          }
        }),
        _vSmallIconText(Icons.thumb_down_alt_rounded, "不喜欢"),
        _vSmallIconText(Icons.monetization_on, "${widget.model.videoInfo.coin}",
            onClick: widget.onCoin),
        _vSmallIconText(
            Icons.grade_rounded, countFormat(widget.model.videoInfo.favorite),
            tiny: widget.model.isFavorite,
            onClick:(){
              var isFavorite = widget.model.isFavorite;
              if(isFavorite){
                widget.unFavorite?.call();
              }else{
                widget.onFavorite?.call();
              }
            }),
        _vSmallIconText(
            Icons.share_rounded, countFormat(widget.model.videoInfo.share),
            onClick: widget.onShared),
      ],
    );
  }

  _vSmallIconText(IconData? data, String txt,
      {VoidCallback? onClick, bool tiny = false}) {
    return InkWell(
      onTap: () {
        onClick?.call();
      },
      child: Column(
        children: [
          Icon(
            data,
            size: 20,
            color: tiny ? primary : Colors.grey,
          ),
          const Padding(padding: EdgeInsets.only(bottom: 4)),
          Text(
            txt,
            style: const TextStyle(fontSize: 12, color: Colors.grey),
          )
        ],
      ),
    );
  }
}
